﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data;
using DDF.Data.Providers;
using System.Data;
using Chinesys.DataModel.Gateways;
using System.Data.SqlClient;

namespace Chinesys.DataModel.Repositories
{
    public static partial class CrawledProductsRepository
    {
        public static void TruncateTable()
        {
            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                string sql = "TRUNCATE TABLE CrawledProducts";

                database.NewCommand(sql, CommandType.Text);
                database.ExecuteNonQuery();
            }
        }

        public static void BulkCopy(List<CrawledProductRow> products)
        {
            SqlBulkCopy bulkCopy = new SqlBulkCopy(connString);
            bulkCopy.DestinationTableName = "CrawledProducts";

            DataTable table = DataModelHelper.ListToDataTable<CrawledProductRow>(products);

            bulkCopy.WriteToServer(table);
        } 
    }
}
